package com.itheima.controller;


import com.itheima.common.entity.Result;
import com.itheima.pojo.OrderSetting;
import com.itheima.service.OrderSettingService;
import com.itheima.common.constant.MessageConstant;
import com.itheima.vo.OrderSettingVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalDate;
import java.util.ArrayList;

@RequestMapping("/ordersetting")
@RestController
public class OrderSettingController {

    @Autowired
    private OrderSettingService orderSettingService;

    /**
     * 根据日期修改可预约人数
     * @param orderSetting
     * @return
     */
    @PostMapping("/editNumberByOrderDate")
    public Result editNumberByOrderDate(@RequestBody OrderSetting orderSetting){
        orderSettingService.editNumberByOrderDate(orderSetting);
        return new Result(true, MessageConstant.ORDERSETTING_SUCCESS);
    }

    /**
     * 根据年月查询对应的预约设置信息
     * @param month
     * @return
     */
    @GetMapping("/getOrderSettingByMonth")
    public Result getOrderSettingByMonth(String month){
        ArrayList<OrderSettingVO> orderSettings = orderSettingService.getOrderSettingByMonth(month);
        return new Result(true, MessageConstant.GET_ORDERSETTING_SUCCESS,orderSettings);
    }

    /**
     * 下载预约信息模版
     * @param response
     */
    @GetMapping("/download")
    public String downloadTemplate(HttpServletResponse response,String filename){

        orderSettingService.downloadTemplate(response,filename);

        return "下载成功";

    }

    /**
     * 上传预约信息
     * @param excelFile
     * @return
     */
    @PostMapping("/upload")
    public Result upload(MultipartFile excelFile){
        orderSettingService.upload(excelFile);

        return new Result(true,MessageConstant.ORDERSETTING_SUCCESS);
    }
}
